package seperator;

import java.util.ArrayList;

import utility.DataFilter;
import words.AWL;
import words.PreList;

public class AWLSeperator extends SeperatorAbstract {

	private AWL awl;
	private PreList awlist;
	private String[] awls;

	public AWLSeperator() {
		super();
		this.awl = new AWL();
		this.awlist = PreList.getInstance();
		this.awls = PreList.getawl();
	}

	public void seperate() {
		String[] data = super.getData();
		ArrayList<String> temp_list = new ArrayList<String>();
		for (int i = 0; i < data.length; i++) {
			if (!(data[i].isEmpty())) {
				for (int j = 0; j < awls.length; j++) {

					String data_lowercase = data[i].toLowerCase();
					String awl_lowercase = awls[j].toLowerCase();
					if (data_lowercase.contains(awl_lowercase)) {
						/*
						 * detect the length difference to avoid enormous
						 * contain 'norm'
						 */
						int length_max_dif = 2;
						int length_dif = data_lowercase.length()
								- awl_lowercase.length();
						if (length_dif <= length_max_dif) {
							String[] list = temp_list
									.toArray(new String[temp_list.size()]);
							if (!DataFilter.isexisted(awls[j], list)) {
								temp_list.add(awls[j]);
							}

						}

					}
				}
			}

		}
		for (int i = 0; i < temp_list.size(); i++) {
			this.awl.input(temp_list.get(i));
		}

	}

	public AWL getAWL() {
		return this.awl;
	}
}
